package com.bckj.fastboot.flow.model;

import com.bckj.fastboot.flow.process.BpmnVisitor;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

@Getter
public class BpmnParallelGateway extends BpmnElement {

    private final List<String> parallelPaths = new ArrayList<>();
    @Setter
    private String startId;
    @Setter
    private String endId;

    public BpmnParallelGateway(String id, String name, String type) {
        super(id, name, type);
    }


    public void addParallelPath(String path) {
        parallelPaths.add(path);
    }

    @Override
    public void accept(BpmnVisitor visitor) {
        visitor.visit(this);
    }

    public boolean isStart() {
        int incomingFlowsSize = getIncomingFlows().size();
        int outgoingFlowsSize = getOutgoingFlows().size();
        return incomingFlowsSize == 1 && outgoingFlowsSize > 1;
    }

    public void validation() {
        if (getIncomingFlows().size() == 1 && getOutgoingFlows().size() ==1) {
            throw new IllegalArgumentException("并行网关配置错误，入边出边不能同时为1");
        }
    }
}
